﻿<%@ Page Language="C#" MasterPageFile="~/admin.master" AutoEventWireup="true" Inherits="MediaMonitor.Admin.Company_Mgmt_AddEdit"
    Theme="default" Title="Client Management" CodeBehind="company-mgmt-addedit.aspx.cs" %>
<%@ Import Namespace="Adex" %>
<%@ Import Namespace="MediaMonitor.Common" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 

<asp:Content ID="Content1" ContentPlaceHolderID="Head" Runat="Server">
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script src="../rad-scripts/rad.js" type="text/javascript"></script>  
    </telerik:RadCodeBlock>


   

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Body" Runat="Server">
     
    <asp:UpdatePanel ID="pnlUpdate" runat="server">
        <ContentTemplate>
    <asp:HiddenField ID="hdnFormMode" runat="server" Value="add" />
    <asp:HiddenField ID="hdnCurPkId" runat="server" Value="0" />

    <asp:Panel ID="pnlIno" runat="server" Visible="false">
    <asp:Label ID="lblMsg" runat="server" SkinID="Error" />
    <br /><br />
    
    <ul>
        <li><a class="BigLink" href="company-mgmt-list.aspx">List of Clients</a></li>
        <li><a class="BigLink" href="company-mgmt-addedit.aspx">Add New Client</a></li>       
    </ul> 
    
    </asp:Panel>

    <asp:Panel ID="pnlForm" runat="server">
    <table width="95%">

        <tr>
            <td colspan="4">
                <asp:Label ID="lblMsg_top" runat="server" SkinID="Error" />
            </td>
        </tr>
        <tr>
            <td>
                
            </td>
            <td colspan="3">

                <asp:ImageButton ID="btnAdd_top" runat="server" SkinID="Add" OnClick="btnAdd_Click"
                    ValidationGroup="form" />
                <asp:ImageButton ID="btnUpdate_top" runat="server" SkinID="Update" OnClick="btnUpdate_Click"
                    ValidationGroup="form" />
                <asp:ImageButton ID="btnDelete_top" runat="server" SkinID="Delete" OnClick="btnDelete_Click"
                    CausesValidation="false" />
                <asp:ImageButton ID="btnCancel_top" runat="server" SkinID="Cancel" OnClick="btnCancel_Click"
                    CausesValidation="false" /> <br />
                    
            </td>
        </tr>
        <tr>
            <td colspan="4">
                <asp:ValidationSummary ID="vSummary" runat="server" ValidationGroup="form" />
            </td>
        </tr>
        <tr>
            <td>
                <b>Company Name (Client):</b></td>
            <td><asp:TextBox ID="tbCompanyName" runat="server" ValidationGroup="form" Width="300" />
                <asp:RequiredFieldValidator ID="rfvCompName" runat="server" ControlToValidate="tbCompanyName"
                    ErrorMessage="Company Name required" Text="*" Display="Dynamic" ValidationGroup="form" />
            </td>
           
        </tr>

        <tr>
            <td><b>Company Login Name</b></td>
            <td><asp:TextBox ID="tbLoginName" runat="server" />
                <asp:RequiredFieldValidator ID="rfvLogin" runat="server" ControlToValidate="tbLoginName" ErrorMessage="Plz Enter a Login Name" Text="*" Display="Dynamic" ValidationGroup="form" />
                <asp:RegularExpressionValidator ID="revLoginNae" runat="server" ControlToValidate="tbLoginName"
                    Display="Dynamic" ValidationGroup="form" Text="Invalid login name" ErrorMessage="Login name rule: All small letters, alpha numeric text without spaces.&nbsp; &#39;-&#39; &amp; &#39;_&#39; are allowed. Minimum 2 letters, maximum 50 letters" ValidationExpression="\b[a-z0-9_-]{2,50}\b"></asp:RegularExpressionValidator>
            </td>
        </tr>
        <tr>
            <td>
                <b>Password</b>
            </td>
            <td>
                <asp:TextBox ID="tbPassword" runat="server" />
                <asp:RequiredFieldValidator ID="rfvPassword" runat="server" ControlToValidate="tbPassword" Display="Dynamic" ErrorMessage="Password required" Text="*" ValidationGroup="form" />
            </td>
        </tr> 

        <tr>
            <td><b>Contact Email</b></td>
            <td><asp:TextBox ID="tbEmail" runat="server" />
                <asp:RegularExpressionValidator ErrorMessage="Invalid Email Address" ID="revEmail" ValidationGroup="form" runat="server" Text="Invalid"
                    ControlToValidate="tbEmail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                    Display="Dynamic" />
                <asp:RequiredFieldValidator ID="rfvEmail" runat="server" ValidationGroup="form" ControlToValidate="tbEmail"
                    Display="Dynamic" ErrorMessage="Contact Email required" Text="*"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td>
                <b>Credits</b>
            </td>
            <td>
                <asp:TextBox ID="tbCredits" runat="server" Text="0" ValidationGroup="form" />
                <asp:RangeValidator ID="rvCredits" runat="server" Type="Integer" MinimumValue="0"
                    MaximumValue="9999999" ErrorMessage="Invalid Credits" Text="*" ControlToValidate="tbCredits"
                    Display="Dynamic" ValidationGroup="form" />
                <asp:CheckBox ID="chkUnlimitedCredits" AutoPostBack="true" runat="server" Text="Unlimited" Checked="false" TextAlign="Right"  />
                <script type="text/javascript">
                
                    function SetUnlimitedCredits() {
                        var tbCredits = document.getElementById('<%=tbCredits.ClientID%>');
                         //alert(tbCredits);
                        if (this.checked) {
                            tbCredits.disabled = true;
                            tbCredits.value = "9999999";
                        }
                        else
                            tbCredits.disabled = false;
                    } 

                    document.getElementById('<%=chkUnlimitedCredits.ClientID%>').onclick = SetUnlimitedCredits;
                </script>
            </td>
        </tr>
        <tr>
            <td>
                <b>Active:</b>
            </td>
            <td>
                <asp:CheckBox ID="chkAcitve" runat="server" />
            </td>
        </tr>
         <tr>
            <td>
                <b>No Summary:</b>
            </td>
            <td>
                <asp:CheckBox ID="chkNoSummary" runat="server" />
            </td>
        </tr>
        <tr>
            <td>
                <b>Valid From:</b>
            </td>
            <td colspan="3">
                <!--Start Date Control-->
                <asp:TextBox Width="100" ID="tbValidFrom" runat="server" ValidationGroup="form"> </asp:TextBox>
                <img alt="Calendar" onclick="setActiveStyleSheet(this, 'blue'); return showCalendar('<%=tbValidFrom.ClientID%>', 'mm/dd/y');"
                    src="<%=Utility.AppPath%>/js/calendar/calendar3.png" style="display: inline; vertical-align: top" />
                <asp:CustomValidator ID="cvDateStart" runat="server" ClientValidationFunction="checkDate"
                    ValidationGroup="form" ControlToValidate="tbValidFrom" Display="Dynamic" ErrorMessage="Invalid Date in valid From box." Text="invalid"></asp:CustomValidator>
                <asp:RequiredFieldValidator ID="rfvDateStart" runat="server" ControlToValidate="tbValidFrom"
                    ValidationGroup="form" Display="Dynamic" ErrorMessage="Valid From date is required" Text="*"></asp:RequiredFieldValidator>
                <!--End Date Control-->
             
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <b>Valid To:</b>
              
                <!--Start Date Control-->
                <asp:TextBox Width="100" ID="tbValidTo" runat="server" ValidationGroup="form"> </asp:TextBox>
                <img alt="Calendar" onclick="setActiveStyleSheet(this, 'blue'); return showCalendar('<%=tbValidTo.ClientID%>', 'mm/dd/y');"
                    src="<%=Utility.AppPath%>/js/calendar/calendar3.png" style="display: inline;
                    vertical-align: top" />
                <asp:CustomValidator ID="cvDateEnd" runat="server" ClientValidationFunction="checkDate"
                    ValidationGroup="form" ControlToValidate="tbValidTo" Display="Dynamic" ErrorMessage="Invalid Date in Valid to box." Text="Invalid"></asp:CustomValidator>
                <asp:RequiredFieldValidator ID="rfvDateEnd" runat="server" ControlToValidate="tbValidTo"
                    ValidationGroup="form" Display="Dynamic" ErrorMessage="Valid to date required" Text="*"></asp:RequiredFieldValidator>
                <!--End Date Control-->
            </td>
        </tr>
        <tr>
            <td><b>Price Per Second</b></td>
            <td>
                <asp:DropDownList ID="lstPriceKey" runat="server" DataTextField="Value" DataValueField="AppSettingID" ValidationGroup="form"></asp:DropDownList>

                <asp:RequiredFieldValidator ID="rfvPrice" runat="server" ErrorMessage="Select Price per Second" Text="*" ControlToValidate="lstPriceKey" InitialValue="0" Display="Dynamic" ValidationGroup="form" />
            </td>
        </tr>
       
        <tr>
            <td>
                <b>Modules:</b>
            </td>
            <td colspan="3">
                <div style="width: 85%; height: 100px; min-width:650px; border: solid 2px #988989">
                <asp:CheckBoxList ID="lstModules" runat="server" DataTextField="ModuleName"
                    DataValueField="ModuleID" RepeatColumns="3" RepeatDirection="Horizontal" Width="100%" />
                </div>
            </td>
        </tr>
        <tr >
         <td>
                <b>Advertisers:</b>
            
            <td colspan="3">
            <div style="width: 85%; height: 100px; min-width:650px; border: solid 2px #988989">
                <asp:CheckBoxList ID="lstchkAdvertiser" runat="server" DataTextField="Advertiser"
                     RepeatColumns="3" RepeatDirection="Horizontal" Width="100%" />
                </div>
            </td>
        </tr>
        <tr>
            <td>
            <br /><br />
                <b>News Template</b>

            </td>
            <td colspan="3">
                <br />
                <br />
                <br />
                <asp:DropDownList ID="lstNewsTemplate" runat="server" DataTextField="TemplateName" DataValueField="TemplateID" Font-Size="12" />
                <br />
                <br />
             </td>
        </tr>
       <%-- Categories--%>
        <tr valign="top">
            <td>
                <br /><br /><br /><br /><br /><br />
                <b>Categories</b></td>
            <td colspan="3">
            <b>Selected Categories:</b>
                <%
                    if (Session["CurDtSalCats_CompMgmtPage"] != null)
                    {
                        DataTable dtSelCats = (DataTable)Session["CurDtSalCats_CompMgmtPage"];
                        if (dtSelCats.Rows.Count == 0)
                        {  %>
                            No category selected.
                      <%}
                    }
                    else { 
                    %>
                    No category selected.
                    <%
                    }  
                %>
                <br /><br />
               
            <asp:DataList ID="rptSelCats" runat="server" RepeatColumns="10" CellSpacing="10" RepeatDirection="Horizontal">
                <ItemTemplate>
                    <div style=" display: inline; margin-top:5px; border:solid 1px #bbb; padding:3px;" title='<%#Eval("CategoryName")%>'>
                    <%#Eval("CategoryCode")%> <asp:LinkButton ID="lnkDelSelCatCode" runat="server" OnClick="DelSelCatCode" CommandArgument='<%#Eval("CategoryID")%>' ToolTip='<%#Eval("CategoryName")%>'>
                        <div style="text-align:center; background-color:Red; color:White; font-weight:bold; padding:3px; width:14px; display:inline;">
                             X&nbsp;
                        </div>
                    </asp:LinkButton>
                    </div>

                </ItemTemplate> 
            </asp:DataList>
            <br />
                <asp:CheckBox ID="chkUnlimitedCategories" runat="server" Checked="false" AutoPostBack="true"
                    OnCheckedChanged="chkUnlimitedCategories_CheckChanged" />
                Unlimited Categories
            <div style="text-align: right; width: 85%; padding:5px;">
             <asp:Button ID="btnSelCats" Text="Add Selected Categories" OnClick="AddSelCats" runat="server" CausesValidation="false" />
            </div>

            <telerik:RadGrid ID="radGridCats" runat="server" AllowFilteringByColumn="True" AllowPaging="True"
                    AllowSorting="True" GridLines="None" Skin="Hay" OnNeedDataSource="radGridCats_NeedDataSource"
                    Width="85%"  AutoGenerateColumns="false" GroupingSettings-CaseSensitive="false"
                    PageSize="10" AllowMultiRowSelection="true" OnItemDataBound="radGridCats_ItemDataBound">
                    <MasterTableView DataKeyNames="CategoryCode, CategoryName,CategoryID">
                        <Columns>
                            <telerik:GridClientSelectColumn ButtonType="LinkButton" Text="Select"  />
                            
                            <telerik:GridBoundColumn  AutoPostBackOnFilter="true" DataField="CategoryCode" HeaderText="Category Code" UniqueName="CategoryCode" FilterControlWidth="50" />
                            <telerik:GridBoundColumn  AutoPostBackOnFilter="true" DataField="CategoryName" HeaderText="Category Name" ItemStyle-Font-Size="Smaller" />
                            <telerik:GridBoundColumn DataField="SectorName" HeaderText="Sector" ItemStyle-Font-Size="Smaller" AutoPostBackOnFilter="true"  /> 
                    <%--     <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="MediaType"  HeaderText="Media Type" ItemStyle-Font-Size="Smaller" />--%>
                                   
                        </Columns>
                    </MasterTableView>
                    <ClientSettings EnableRowHoverStyle="true">
                        <Selecting AllowRowSelect="true" /> 
                        <ClientEvents OnFilterMenuShowing="filterMenuShowing" />
                    </ClientSettings>
                    <FilterMenu OnClientShowing="MenuShowing" />
                </telerik:RadGrid>
                 
            </td>
        </tr>
        <caption>
            <br />
            <br />
            <%--New Commercial Categories--%>
            <tr valign="top">
                <td>
                    <br />
                    <br />
                    <br />
                    <br />
                    <br />
                    <br />
                    <b>New Commercial Categories</b></td>
                <td colspan="3">
                    <b>Selected Commercial Categories:</b>
                    <%
                    if (Session["CurDtSalNewCats_CompMgmtPage"] != null)
                    {
                        DataTable dtSelCats = (DataTable)Session["CurDtSalNewCats_CompMgmtPage"];
                        if (dtSelCats.Rows.Count == 0)
                        {  %>No Commercial category selected.
                    <%}
                    }
                    else { 
                    %>No Commercial category selected.
                    <%
                    }  
                %>
                    <br />
                    <br />
                    <asp:DataList ID="rptSelnewCats" runat="server" CellSpacing="10" 
                        RepeatColumns="10" RepeatDirection="Horizontal">
                        <ItemTemplate>
                            <div style=" display: inline; margin-top:5px; border:solid 1px #bbb; padding:3px;" 
                                title='<%#Eval("CategoryName")%>'>
                                <%#Eval("CategoryCode")%>
                                <asp:LinkButton ID="lnkDelSelCatCode" runat="server" 
                                    CommandArgument='<%#Eval("CategoryID")%>' OnClick="DelNewSelCatCode" 
                                    ToolTip='<%#Eval("CategoryName")%>'>
                        <div style="text-align:center; background-color:Red; color:White; font-weight:bold; padding:3px; width:14px; display:inline;">
                             X&nbsp;
                        </div>
                    </asp:LinkButton>
                            </div>
                        </ItemTemplate>
                    </asp:DataList>
                    <br />
                    <asp:CheckBox ID="chkUnlimitedNewCategories" runat="server" AutoPostBack="true" 
                        Checked="false" OnCheckedChanged="chkUnlimitedNewCategories_CheckChanged" />
                    Unlimited Commercial Categories
                    <div style="text-align: right; width: 85%; padding:5px;">
                        <asp:Button ID="btnSelNewCats" runat="server" CausesValidation="false" 
                            OnClick="AddNewSelCats" Text="Add Selected Commercial Categories" />
                    </div>
                    <telerik:RadGrid ID="radGridNewCats" runat="server" 
                        AllowFilteringByColumn="True" AllowMultiRowSelection="true" AllowPaging="True" 
                        AllowSorting="True" AutoGenerateColumns="false" GridLines="None" 
                        GroupingSettings-CaseSensitive="false" 
                        OnNeedDataSource="radGridNewCats_NeedDataSource" PageSize="10" Skin="Hay" 
                        Width="85%" OnItemDataBound="radGridNewCats_ItemDataBound">
                        <MasterTableView DataKeyNames="CategoryCode, CategoryName, CategoryID">
                            <Columns>
                                <telerik:GridClientSelectColumn ButtonType="LinkButton" Text="Select" />
                                <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="CategoryCode" 
                                    FilterControlWidth="50" HeaderText="Category Code" UniqueName="CategoryCode" />
                                <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="CategoryName" 
                                    HeaderText="Category Name" ItemStyle-Font-Size="Smaller" />
                                <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="SectorName" 
                                    HeaderText="Sector" ItemStyle-Font-Size="Smaller" />
                                  <%--  <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="MediaType" 
                                    HeaderText="Media Type" ItemStyle-Font-Size="Smaller" />--%>
                            </Columns>
                        </MasterTableView>
                        <ClientSettings EnableRowHoverStyle="true">
                            <Selecting AllowRowSelect="true" />
                            <ClientEvents OnFilterMenuShowing="filterMenuShowing" />
                        </ClientSettings>
                        <FilterMenu OnClientShowing="MenuShowing" />
                    </telerik:RadGrid>
                </td>
            </tr>
            <%--Footer--%>
            <tr>
                <td valign="top">
                    <br />
                    <br />
                    <b>Logo:</b>
                </td>
                <td valign="top">
                    <br />
                    <br />
                    <asp:FileUpload ID="flLogo" runat="server" />
                    <br />
                    <br />
                    <asp:Image ID="imgLog" runat="server" 
                        ImageUrl="~/images/companies/tn/noimage.jpg" />
                    <br />
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td colspan="3">
                    <br />
                    <asp:ImageButton ID="btnAdd" runat="server" onclick="btnAdd_Click" SkinID="Add" 
                        ValidationGroup="form" />
                    <asp:ImageButton ID="btnUpdate" runat="server" OnClick="btnUpdate_Click" 
                        SkinID="Update" ValidationGroup="form" />
                    <asp:ImageButton ID="btnDelete" runat="server" CausesValidation="false" 
                        onclick="btnDelete_Click" SkinID="Delete" />
                    <asp:ImageButton ID="btnCancel" runat="server" CausesValidation="false" 
                        OnClick="btnCancel_Click" SkinID="Cancel" />
                </td>
            </tr>
        </caption>
        
    </table>
    </asp:Panel>
     
   
        </ContentTemplate>
        <Triggers>
            <asp:PostBackTrigger ControlID="btnAdd" />
            <asp:PostBackTrigger ControlID="btnUpdate" />
            <asp:PostBackTrigger ControlID="btnAdd_top" />
            <asp:PostBackTrigger ControlID="btnUpdate_top" />
        </Triggers>
    </asp:UpdatePanel>
    <%--</telerik:RadAjaxPanel>--%>
</asp:Content>

